package multithreading;

/**
 * 三个窗口买票，100张
 * 继承、同步方法
 *
 * @author DuJiabao
 * @create 2020-12-13 17:51
 */
public class SaleTicket3 {
    public static void main(String[] args) {
        Windows3 win1 = new Windows3();
        Windows3 win2 = new Windows3();
        Windows3 win3 = new Windows3();

        win1.start();
        win2.start();
        win3.start();
    }

}


class Windows3 extends Thread {
    private static int total = 10000;

    @Override
    public void run() {
        super.run();
        while (true) {
            if (!show()) {
                break;
            }
        }
    }

    private static synchronized boolean show() {
        if (total <= 0)
            return false;
        System.out.println(Thread.currentThread().getName() + ": " + total--);
        return true;
    }

}
